home *** CD-ROM | disk | FTP | other *** search
- Subject: v25i027: Monitor network utilization in terms of ``busiest hosts''
- Newsgroups: comp.sources.unix
- Approved: vixie@pa.dec.com
-
- Submitted-By: Guy Cardwell <gcardwel@okazaki.acs.uci.edu>
- Posting-Number: Volume 25, Issue 27
- Archive-Name: ethertop
-
- This utility displays the top N hosts in terms of how much they are using
- your ethernet. This program depends on Sun's rpc.etherd, and uses curses.
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: MANIFEST Makefile README buffer.c buffer.h copyright
- # ethertop.c ethertop.h ethertop.man hostname.c patchlevel.h
- # screen.c sort.c sort.h
- # Wrapped by vixie@cognition.pa.dec.com on Fri Dec 13 18:24:08 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(530 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1
- X Makefile 1
- X README 1
- X buffer.c 1
- X buffer.h 1
- X copyright 1
- X ethertop.c 1
- X ethertop.h 1
- X ethertop.man 1
- X hostname.c 1
- X patchlevel.h 1
- X screen.c 1
- X sort.c 1
- X sort.h 1
- END_OF_FILE
- if test 530 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(5807 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- BINDIR=/usr/local/bin
- MANDIR=/usr/man/manl
- MANEXT=l
- CC=cc -O
- X
- all: ethertop
- X
- ethertop: ethertop.o sort.o buffer.o hostname.o ether_clnt.o ether_xdr.o
- X $(CC) -o ethertop ethertop.o sort.o buffer.o hostname.o ether_clnt.o ether_xdr.o -lcurses -ltermcap -lm
- X
- depend: ether.h
- X makedepend *.c *.h
- X
- clean:
- X rm -f *.o *~ ethertop TAGS ether.h ether_clnt.c ether_svc.c ether_xdr.c ether.x
- X
- dist: README Makefile copyright buffer.c ethertop.c hostname.c screen.c sort.h buffer.h ethertop.h patchlevel.h sort.c ethertop.man
- X shar README Makefile copyright buffer.c ethertop.c hostname.c screen.c sort.h buffer.h ethertop.h patchlevel.h sort.c ethertop.man >ethertop.shar
- X
- ether.h: /usr/include/rpcsvc/ether.x
- X cp /usr/include/rpcsvc/ether.x .
- X rpcgen ether.x
- X
- install: ethertop
- X install -c -m 755 ethertop $(BINDIR)
- X
- install.man: ethertop.man
- X install -c -m 644 ethertop.man $(MANDIR)/ethertop.$(MANEXT)
- X
- X# DO NOT DELETE THIS LINE -- make depend depends on it.
- X
- buffer.o: buffer.h /usr/include/stdio.h
- ether_clnt.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
- ether_clnt.o: /usr/include/malloc.h /usr/include/sys/types.h
- ether_clnt.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
- ether_clnt.o: /usr/include/sys/time.h /usr/include/sys/time.h
- ether_clnt.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
- ether_clnt.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
- ether_clnt.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
- ether_clnt.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
- ether_clnt.o: /usr/include/rpc/svc_auth.h ether.h
- ether_svc.o: /usr/include/stdio.h /usr/include/rpc/rpc.h
- ether_svc.o: /usr/include/rpc/types.h /usr/include/malloc.h
- ether_svc.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
- ether_svc.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
- ether_svc.o: /usr/include/sys/time.h /usr/include/netinet/in.h
- ether_svc.o: /usr/include/rpc/xdr.h /usr/include/rpc/auth.h
- ether_svc.o: /usr/include/rpc/clnt.h /usr/include/rpc/rpc_msg.h
- ether_svc.o: /usr/include/rpc/auth_unix.h /usr/include/rpc/auth_des.h
- ether_svc.o: /usr/include/rpc/svc.h /usr/include/rpc/svc_auth.h ether.h
- ether_xdr.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
- ether_xdr.o: /usr/include/malloc.h /usr/include/sys/types.h
- ether_xdr.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
- ether_xdr.o: /usr/include/sys/time.h /usr/include/sys/time.h
- ether_xdr.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
- ether_xdr.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
- ether_xdr.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
- ether_xdr.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
- ether_xdr.o: /usr/include/rpc/svc_auth.h ether.h
- ethertop.o: /usr/include/stdio.h /usr/include/curses.h /usr/include/sgtty.h
- ethertop.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h
- ethertop.o: /usr/include/sys/ttydev.h /usr/include/sys/ttold.h
- ethertop.o: /usr/include/sys/ioccom.h /usr/include/sys/ttycom.h
- ethertop.o: /usr/include/sys/filio.h /usr/include/sys/sockio.h
- ethertop.o: /usr/include/signal.h /usr/include/sys/signal.h
- ethertop.o: /usr/include/vm/faultcode.h /usr/include/ctype.h
- ethertop.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
- ethertop.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
- ethertop.o: /usr/include/sys/time.h /usr/include/math.h
- ethertop.o: /usr/include/floatingpoint.h /usr/include/sys/ieeefp.h ethertop.h
- ethertop.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
- ethertop.o: /usr/include/malloc.h /usr/include/netinet/in.h
- ethertop.o: /usr/include/rpc/xdr.h /usr/include/rpc/auth.h
- ethertop.o: /usr/include/rpc/clnt.h /usr/include/rpc/rpc_msg.h
- ethertop.o: /usr/include/rpc/auth_unix.h /usr/include/rpc/auth_des.h
- ethertop.o: /usr/include/rpc/svc.h /usr/include/rpc/svc_auth.h ether.h
- ethertop.o: buffer.h sort.h
- hostname.o: /usr/include/stdio.h /usr/include/sys/types.h
- hostname.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
- hostname.o: /usr/include/sys/socket.h /usr/include/netdb.h
- hostname.o: /usr/include/string.h ethertop.h /usr/include/rpc/rpc.h
- hostname.o: /usr/include/rpc/types.h /usr/include/malloc.h
- hostname.o: /usr/include/sys/time.h /usr/include/sys/time.h
- hostname.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
- hostname.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
- hostname.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
- hostname.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
- hostname.o: /usr/include/rpc/svc_auth.h ether.h
- sort.o: /usr/include/stdio.h ethertop.h /usr/include/rpc/rpc.h
- sort.o: /usr/include/rpc/types.h /usr/include/malloc.h
- sort.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
- sort.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
- sort.o: /usr/include/sys/time.h /usr/include/netinet/in.h
- sort.o: /usr/include/rpc/xdr.h /usr/include/rpc/auth.h
- sort.o: /usr/include/rpc/clnt.h /usr/include/rpc/rpc_msg.h
- sort.o: /usr/include/rpc/auth_unix.h /usr/include/rpc/auth_des.h
- sort.o: /usr/include/rpc/svc.h /usr/include/rpc/svc_auth.h ether.h buffer.h
- ether.o: /usr/include/rpc/types.h /usr/include/malloc.h
- ether.o: /usr/include/sys/types.h /usr/include/sys/stdtypes.h
- ether.o: /usr/include/sys/sysmacros.h /usr/include/sys/time.h
- ether.o: /usr/include/sys/time.h
- ethertop.o: /usr/include/rpc/rpc.h /usr/include/rpc/types.h
- ethertop.o: /usr/include/malloc.h /usr/include/sys/types.h
- ethertop.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h
- ethertop.o: /usr/include/sys/time.h /usr/include/sys/time.h
- ethertop.o: /usr/include/netinet/in.h /usr/include/rpc/xdr.h
- ethertop.o: /usr/include/rpc/auth.h /usr/include/rpc/clnt.h
- ethertop.o: /usr/include/rpc/rpc_msg.h /usr/include/rpc/auth_unix.h
- ethertop.o: /usr/include/rpc/auth_des.h /usr/include/rpc/svc.h
- ethertop.o: /usr/include/rpc/svc_auth.h ether.h
- END_OF_FILE
- if test 5807 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(553 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- Installing ethertop is easy.
- X
- There is an install target and an install.man target. Adjust
- the directory locations in the Makefile for your binaries
- directory, you man pages directories, and the manual page
- extension you use. Then type make and make install. make clean
- cleans up the mess.
- X
- There is a little hangup with dependences with the rpcgen. If you
- delete the rpcgen generated code, you may have to type make twice.
- X
- If you are building under something other than SunOS 4.1.1, you may
- want to run make depend.
- X
- X
- Guy Cardwell
- gcardwel@uci.edu
- END_OF_FILE
- if test 553 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'buffer.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'buffer.c'\"
- else
- echo shar: Extracting \"'buffer.c'\" \(1472 characters\)
- sed "s/^X//" >'buffer.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X#include "buffer.h"
- X#include <stdio.h>
- X
- void add_buffer(buf, entry)
- buffer *buf;
- void *entry;
- X{
- X buf->p[buf->end]=entry;
- X buf->end++;
- X if (buf->end == buf->len)
- X {
- X fprintf(stderr,"reallocing buffer\n");
- X buf->len+=BUFLEN;
- X buf->p=(void **)realloc(buf->p,buf->len);
- X }
- X}
- X
- void clear_buffer(buf)
- buffer *buf;
- X{
- buf->end=0;
- X}
- X
- void free_buffer(buf)
- buffer *buf;
- X{
- unsigned int i;
- for (i=0; i<buf->end; i++)
- X free(buf->p[i]);
- buf->end=0;
- X}
- X
- X
- buffer *init_buffer()
- X{
- X buffer *buf;
- X
- X buf= (buffer *) malloc (sizeof(buffer));
- X buf->p=(void **) malloc(BUFLEN*sizeof(void *));
- X buf->end=0;
- X buf->len=BUFLEN;
- X return (buf);
- X}
- X
- X
- X
- X
- END_OF_FILE
- if test 1472 -ne `wc -c <'buffer.c'`; then
- echo shar: \"'buffer.c'\" unpacked with wrong size!
- fi
- # end of 'buffer.c'
- fi
- if test -f 'buffer.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'buffer.h'\"
- else
- echo shar: Extracting \"'buffer.h'\" \(1013 characters\)
- sed "s/^X//" >'buffer.h' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X#define BUFLEN 1024
- X
- X
- typedef struct {
- X void **p;
- X unsigned int end;
- X unsigned int len;
- X } buffer;
- X
- X
- void add_buffer();
- buffer *init_buffer();
- void clear_buffer();
- void free_buffer();
- END_OF_FILE
- if test 1013 -ne `wc -c <'buffer.h'`; then
- echo shar: \"'buffer.h'\" unpacked with wrong size!
- fi
- # end of 'buffer.h'
- fi
- if test -f 'copyright' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'copyright'\"
- else
- echo shar: Extracting \"'copyright'\" \(819 characters\)
- sed "s/^X//" >'copyright' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- END_OF_FILE
- if test 819 -ne `wc -c <'copyright'`; then
- echo shar: \"'copyright'\" unpacked with wrong size!
- fi
- # end of 'copyright'
- fi
- if test -f 'ethertop.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ethertop.c'\"
- else
- echo shar: Extracting \"'ethertop.c'\" \(10135 characters\)
- sed "s/^X//" >'ethertop.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X#include <stdio.h>
- X#include <curses.h>
- X#include <signal.h>
- X#include <ctype.h>
- X#include <sys/types.h>
- X#include <sys/time.h>
- X#include <math.h>
- X#include "ethertop.h"
- X#include "buffer.h"
- X#include "sort.h"
- X#ifndef lint
- char copyright[]="Copyright (c) 1991 Regents of the University of California. All rights reserved.";
- X#endif
- WINDOW *src_window;
- WINDOW *dest_window;
- WINDOW *size_window1;
- WINDOW *size_window2;
- WINDOW *load_window;
- WINDOW *user_window;
- X
- struct sgttyb tty_settings;
- X
- displayip=FALSE;
- total=FALSE;
- char *server;
- int maxlines;
- X
- void swan_song(message)
- char *message;
- X{
- X clear();
- X mvcur(0, COLS-1, LINES-1, 0);
- X refresh();
- X endwin();
- X perror(message);
- X fflush(stderr);
- X exit(0);
- X}
- X
- void death()
- X{
- X signal(SIGINT, SIG_IGN);
- X clear();
- X mvcur(0, COLS-1, LINES-1, 0);
- X refresh();
- X endwin();
- X exit(0);
- X}
- X
- X/*
- X 1 2 3 4 5 6 7
- X1234567890123456789012345678901234567890123456789012345678901234567890123456789
- X*/
- X/*
- X | | | | | | | | |
- X*/
- X
- X
- void setup_screen()
- X{
- X int x;
- X signal(SIGINT, death);
- X ioctl(0,TIOCGETP,&tty_settings);
- X initscr();
- X maxlines=LINES-9;
- X noecho();
- X crmode();
- X nonl();
- X user_window=newwin(1,0,0,0);
- X scrollok(stdscr,0);
- X load_window=subwin(stdscr,1,0,2,0);
- X size_window1=subwin(stdscr,1,0,5,0);
- X size_window2=subwin(stdscr,1,0,7,0);
- X src_window=subwin(stdscr,LINES-10,39,10,0);
- X dest_window=subwin(stdscr,LINES-10,39,10,41);
- X move(0,0);
- X printw("Network load as seen from %s", server);
- X move(1,0);
- X printw(" bytes pkts bcst tcp udp icmp arp nd oth");
- X move(3,0);
- X printw("packet sizes:");
- X move(4,0);
- X printw(" 64-154 155-245 246-336 337-427 428-518 519-609 610-699 700-790");
- X move(6,0);
- X printw("791-881 882-972 973-1063 1064-1154 1155-1245 1246-1336 1337-1427 1428-1518");
- X move(8,0);
- X printw("--------------------------------------------------------------------------------");
- X move(9,0);
- X printw("HOSTNAME SENT | HOSTNAME RECV ");
- X for (x=9; x!=LINES; x++)
- X {
- X move(x,39);
- X addch('|');
- X }
- X}
- X
- void display_data(diffstat)
- etherfloatstat *diffstat;
- X{
- X
- X wmove(load_window,0,0);
- X wprintw(load_window,"%7.2fK %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f",
- X (double) diffstat->e_bytes/1024.0,
- X (double) diffstat->e_packets,
- X (double) diffstat->e_bcast,
- X (double) diffstat->e_proto[3],
- X (double) diffstat->e_proto[2],
- X (double) diffstat->e_proto[1],
- X (double) diffstat->e_proto[4],
- X (double) diffstat->e_proto[0],
- X (double) diffstat->e_proto[5]);
- X
- X wmove(size_window1,0,0);
- X wprintw(size_window1,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f ",
- X (double) diffstat->e_size[0],
- X (double) diffstat->e_size[1],
- X (double) diffstat->e_size[2],
- X (double) diffstat->e_size[3],
- X (double) diffstat->e_size[4],
- X (double) diffstat->e_size[5],
- X (double) diffstat->e_size[6],
- X (double) diffstat->e_size[7]);
- X
- X wmove(size_window2,0,0);
- X wprintw(size_window2,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f ",
- X (double) diffstat->e_size[8],
- X (double) diffstat->e_size[9],
- X (double) diffstat->e_size[10],
- X (double) diffstat->e_size[11],
- X (double) diffstat->e_size[12],
- X (double) diffstat->e_size[13],
- X (double) diffstat->e_size[14],
- X (double) diffstat->e_size[15]);
- X
- X}
- X
- void display_a_list(window,buf)
- X WINDOW *window;
- X buffer *buf;
- X{
- X register unsigned int i;
- X etherfloat_node *ptr;
- X for (i=0; i<maxlines && i<buf->end; i++)
- X {
- X wmove(window,i,0);
- X ptr=buf->p[i];
- X wprintw(window, "%-30.30s %7.2f",
- X gethostnamebyip(ptr->h_addr),
- X (double)ptr->h_cnt);
- X }
- X wmove(window,i,0);
- X wclrtobot(window);
- X}
- X
- X/* I am not proud of this routine, but it works */
- int wgnum(window,min,max)
- WINDOW *window;
- int min;
- int max;
- X{
- X int ch;
- X int i=0;
- X int x,y;
- X int maxchar;
- X int minchar;
- X char string[80];
- X bzero(string,80);
- X maxchar=(int) log10 ((double) (max*10));
- X nl();
- X noecho();
- X getyx(window,y,x);
- X while(1)
- X {
- X ch=getch();
- X if ((ch=='\n')
- X && i>0
- X && (atoi(string) <=max)
- X && (atoi(string) >= min) )
- X {
- X nonl();
- X noecho();
- X return(atoi(string));
- X }
- X if(ch==tty_settings.sg_erase)
- X {
- X if(i>0)
- X {
- X string[--i]=0;
- X mvwdelch(window,y,x+i);
- X wrefresh(window);
- X continue;
- X }
- X else
- X {
- X continue;
- X }
- X }
- X if(isdigit(ch))
- X {
- X if (i<maxchar)
- X {
- X string[i++]=ch;
- X mvwaddch(window,y,x+i-1,ch);
- X wrefresh(window);
- X continue;
- X }
- X }
- X }
- X}
- X
- X
- void process_input()
- X{
- X switch(tolower(getch()))
- X {
- X case 'i':
- X displayip=!displayip;
- X break;
- X case 't':
- X total=!total;
- X break;
- X case 'q':
- X death();
- X break;
- X case 'l':
- X wrefresh(curscr);
- X break;
- X case 's':
- X {
- X werase(user_window);
- X wstandout(user_window);
- X waddstr(user_window,"Seconds to delay:");
- X wstandend(user_window);
- X waddstr(user_window," ");
- X touchwin(user_window);
- X wrefresh(user_window);
- X timeout.tv_sec=wgnum(user_window,2,3600);
- X touchwin(stdscr);
- X refresh();
- X break;
- X }
- X case 'n':
- X werase(user_window);
- X wstandout(user_window);
- X waddstr(user_window,"Hosts to display:");
- X wstandend(user_window);
- X waddstr(user_window," ");
- X touchwin(user_window);
- X wrefresh(user_window);
- X maxlines=wgnum(user_window,0,LINES-9);
- X touchwin(stdscr);
- X refresh();
- X break;
- X default:
- X ;
- X }
- X}
- X
- X
- int errflg=0;
- etherfloatstat diffstat;
- etheraddrs old_src_addrs;
- etheraddrs old_dest_addrs;
- etherstat old_stat_data;
- fd_set readfds,tempreadfds;
- struct timeval timeout={5,0};
- struct timeval temptimeout;
- extern char *optarg;
- extern int optind, opterr;
- X
- X
- main(argc, argv)
- X
- X char *argv[];
- X{
- X CLIENT *cl;
- X etherstat *stat_data;
- X etheraddrs *src_addrs;
- X etheraddrs *dest_addrs;
- X buffer *src_buf;
- X buffer *dest_buf;
- X char c;
- X
- X while ((c=getopt(argc, argv, "is:t"))!=-1)
- X switch(c)
- X {
- X case 'i':
- X displayip++;
- X break;
- X
- X case 's':
- X timeout.tv_sec=atol(optarg);
- X if (timeout.tv_sec<2)
- X errflg++;
- X break;
- X
- X case 't':
- X total++;
- X break;
- X
- X case '?':
- X errflg++;
- X break;
- X }
- X
- X if (optind!=argc-1 || errflg)
- X {
- X fprintf(stderr,"Usage:\n");
- X fprintf(stderr,"%s [options] hostname\n\n",argv[0]);
- X fprintf(stderr,"options are:\n");
- X fprintf(stderr,"-i don't map ip numbers to hostnames\n");
- X fprintf(stderr,"-s int seconds between updates. Minimum of 2 seconds.\n");
- X fprintf(stderr,"-t display time averaged totals, rather than instantanous averages\n");
- X exit(2);
- X }
- X server=argv[optind];
- X
- X src_buf=init_buffer();
- X dest_buf=init_buffer();
- X cl = clnt_create(server, ETHERPROG, ETHERVERS, "udp");
- X if (cl == NULL)
- X {
- X clnt_pcreateerror(server);
- X exit(1);
- X }
- X setup_screen();
- X init_gethostnamebyip();
- X FD_ZERO(&readfds);
- X FD_SET(0,&readfds); /* set up stdin for select */
- X
- X
- X if((etherproc_on_1((void *)NULL,cl))==NULL)
- X swan_song("etherproc_on failed. rpc.etherd probably died");
- X
- X if((stat_data=etherproc_getdata_1((void *) NULL, cl))==NULL)
- X swan_song("etherproc_getdata failed. rpc.etherd probably died");
- X
- X old_stat_data=*stat_data;
- X
- X if((src_addrs=etherproc_getsrcdata_1((void *) NULL, cl))==NULL)
- X swan_song("etherproc_getdata failed. rpc.etherd probably died");
- X
- X old_src_addrs=*src_addrs;
- X
- X if( (dest_addrs =etherproc_getdstdata_1((void *) NULL, cl))==NULL)
- X swan_song("etherproc_getdata failed. rpc.etherd probably died");
- X
- X
- X old_dest_addrs=*dest_addrs;
- X sleep(1); /*snewz*/
- X
- X for (;;)
- X {
- X move(2,0);
- X refresh();
- X tempreadfds=readfds;
- X temptimeout=timeout;
- X if(select(3,&tempreadfds,NULL,NULL,&temptimeout))
- X process_input();
- X
- X if( (stat_data=etherproc_getdata_1((void *) NULL, cl))==NULL)
- X swan_song("etherproc_getdata failed. rpc.etherd probably died");
- X
- X subtract_etherstat(stat_data,&old_stat_data,&diffstat);
- X if (total)
- X {
- X xdr_free(xdr_etherstat,stat_data);
- X }
- X else
- X {
- X xdr_free(xdr_etherstat,&old_stat_data);
- X old_stat_data=*stat_data;
- X }
- X
- X display_data(&diffstat);
- X
- X if( (src_addrs =etherproc_getsrcdata_1((void *) NULL, cl))==NULL)
- X swan_song("etherproc_getsrcdata failed. rpc.etherd probably died");
- X
- X subtract_and_sort_etheraddrs(src_addrs, &old_src_addrs, src_buf);
- X
- X if (total)
- X {
- X xdr_free(xdr_etheraddrs,src_addrs);
- X }
- X else
- X {
- X xdr_free(xdr_etheraddrs,&old_src_addrs);
- X old_src_addrs=*src_addrs;
- X }
- X
- X
- X if( (dest_addrs=etherproc_getdstdata_1((void *) NULL, cl))==NULL)
- X swan_song("etherproc_getdstdata failed. rpc.etherd probably died");
- X
- X subtract_and_sort_etheraddrs(dest_addrs, &old_dest_addrs, dest_buf);
- X if (total)
- X {
- X xdr_free(xdr_etheraddrs,dest_addrs);
- X }
- X else
- X {
- X xdr_free(xdr_etheraddrs,&old_dest_addrs);
- X old_dest_addrs=*dest_addrs;
- X }
- X display_a_list(src_window,src_buf);
- X display_a_list(dest_window,dest_buf);
- X free_buffer(src_buf);
- X free_buffer(dest_buf);
- X }
- X}
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- END_OF_FILE
- if test 10135 -ne `wc -c <'ethertop.c'`; then
- echo shar: \"'ethertop.c'\" unpacked with wrong size!
- fi
- # end of 'ethertop.c'
- fi
- if test -f 'ethertop.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ethertop.h'\"
- else
- echo shar: Extracting \"'ethertop.h'\" \(1517 characters\)
- sed "s/^X//" >'ethertop.h' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X#include <rpc/rpc.h>
- X#undef h_addr
- X#include "ether.h"
- X
- X
- struct etherfloat_node {
- X int h_addr;
- X float h_cnt;
- X};
- typedef struct etherfloat_node etherfloat_node;
- extern displayip;
- extern char *server;
- extern struct timeval timeout;
- extern total;
- char *inet_ntoa();
- char *gethostnamebyip();
- void init_gethostnamebyip();
- struct host_ip_ent
- X{
- X int h_addr;
- X char *h_name;
- X struct host_ip_ent *h_nxt;
- X};
- X
- typedef struct host_ip_ent host_ip_ent;
- X#define H2IP_HASH_SIZE 0x2000
- X#define H2IP_HASH_MASK 0x1FFF
- X
- struct etherfloatstat {
- X float e_time;
- X float e_bytes;
- X float e_packets;
- X float e_bcast;
- X float e_size[NBUCKETS];
- X float e_proto[NPROTOS];
- X};
- typedef struct etherfloatstat etherfloatstat;
- X
- X
- X
- X
- X
- X
- X
- X
- X
- END_OF_FILE
- if test 1517 -ne `wc -c <'ethertop.h'`; then
- echo shar: \"'ethertop.h'\" unpacked with wrong size!
- fi
- # end of 'ethertop.h'
- fi
- if test -f 'ethertop.man' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ethertop.man'\"
- else
- echo shar: Extracting \"'ethertop.man'\" \(4091 characters\)
- sed "s/^X//" >'ethertop.man' <<'END_OF_FILE'
- X.TH ethertop 1 "11/26/1991"
- X.SH NAME
- X.B ethertop
- X\- display and update information about the top network using machines
- X.SH SYNOPSIS
- X.B ethertop
- X.B [
- X-it
- X.B ]
- X.B [
- X-s seconds
- X.B ]
- hostname
- X.SH DESCRIPTION
- X.B ethertop
- is a program which displays network usage in the form of
- top(1).
- X.B ethertop
- uses the rpc.etherd(8) server running on the host
- specified host to gather information about the network. traffic(1)
- provides a visual display of this using Sunview.
- X.B ethertop
- is
- purely text based, although an X version is in the works.
- X.B ethertop
- is
- intended for quick diagnosis of network problems. Questions like "who
- is beating on the fileserver" are very quickly answered by a glance at
- the
- X.B ethertop
- statistics. Note that rpc.etherd must be running on a
- machine on the network you are interested in observing. As rpc.etherd
- only sees packets recieved on the interface it is running on, ethertop
- will only monitor traffic on a given subnet. rpc.etherd puts the
- interface it monitors in promiscuous mode, and you must be root to
- start it. Placing the interface in promiscuous mode causes a perforance
- hit as all packets on the network are interpreted.
- X
- X.SH DISPLAY
- The first lines of the display give information about the types of packets
- present on the network during the sample time. Usually, the
- information is given in per second units. Across the top are the
- following statistics: bytes (total bytes per second), pkts (packets per
- second), bcst (broadcast packets per seconds), tcp (tcp packets per
- second), udp (udp packets per second), icmp (icmp packets per second),
- arp (arp packets per second), nd (network disk packets per second), oth
- X(other packets per second). Below those statistics is data on packet
- sizes. These lines show how many packets per second of a particular
- size of packet is being sent on the network.
- The two columns below the packet statistics show the top senders and
- top recievers of packets. Note that there is no direct correlation
- between the two columns on a line per line basis.
- X.SH COMMANDS
- Like top(1),
- X.B ethertop
- runs in CBREAK mode and interprets commands on the
- fly from the terminal. The following keys are meaningful:
- X.TP
- X.B i
- This toggles the IP number to hostname mapping.
- X.B ethertop
- maintains a
- cache of IP to hostname mappings. Hostnames are added to the cache
- as they appear. This prevents beating on NIS or your local nameserver.
- X.TP
- X.B l
- Redraws the screen.
- X.TP
- X.B n
- This changes the the number of hosts displayed. Prompts for a number
- between 0 and the number of available lines on the screen.
- X.TP
- X.B s
- Changes the number of seconds between display updates. Prompts for a number
- greater than 2. Any less than this and the rpc traffic usually becomes
- significantly greater than any other traffic being measured.
- X.TP
- X.B t
- Statistics usually display on a per seconds basis. This can be
- changed with the to reflect total accumulated averages since the start of the
- program rather than during each sample interval.
- X.TP
- X.B q
- Quit ethertop.
- X.SH OPTIONS
- X.TP 15
- X.BI \-s " seconds"
- Specifies the amount of time to between samples and display updates.
- The default value is 5 seconds. The can be set within the program
- with the s command.
- X.TP
- X.B -t
- Specifies that the packet counts and byte counts are to be time averaged since
- the program began running. This is good for looking at long term trends in
- network usage, rather than pinpointing a specific abuser. This can be toggled
- within the program with the t command.
- X
- X.TP
- X.B -i
- Specifies that
- X.B ethertop
- should not map IP numbers to hostnames in the
- display. This can be toggled in the program with the i command.
- X.SH "SEE ALSO"
- rpc.etherd(8C) traffic(1C)
- X.SH BUGS
- Somewhere. The handling for when the remote rpc hosts dies could be
- better. I am implementing packet type and host filters. They will
- appear in the next release. Please feel free to send me bugs, comments,
- and suggestions. This program needed to be written. Lets make it better.
- X.SH AUTHOR
- Guy Cardwell, Office of Academic Computing
- X
- University of California, Irvine
- X
- gcardwel@uci.edu.
- X
- END_OF_FILE
- if test 4091 -ne `wc -c <'ethertop.man'`; then
- echo shar: \"'ethertop.man'\" unpacked with wrong size!
- fi
- # end of 'ethertop.man'
- fi
- if test -f 'hostname.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'hostname.c'\"
- else
- echo shar: Extracting \"'hostname.c'\" \(1850 characters\)
- sed "s/^X//" >'hostname.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/socket.h>
- X#include <netdb.h>
- X#include <string.h>
- X#include "ethertop.h"
- X
- X
- static host_ip_ent *hash_table[H2IP_HASH_SIZE];
- X
- void init_gethostnamebyip()
- X{
- X register int i;
- X for(i=0; i<H2IP_HASH_SIZE; i++)
- X hash_table[i]=NULL;
- X}
- X
- X
- char *gethostnamebyip(h_addr)
- X int h_addr;
- X{
- X register host_ip_ent *ptr;
- X struct hostent *host;
- X host_ip_ent *temp;
- X unsigned int index;
- X if (displayip)
- X {
- X return(inet_ntoa(&h_addr));
- X }
- X index=((unsigned int)h_addr & H2IP_HASH_MASK);
- X
- X for (ptr=hash_table[index] ; ptr!=NULL; ptr=ptr->h_nxt )
- X {
- X if (ptr->h_addr==h_addr)
- X {
- X return(ptr->h_name);
- X }
- X }
- X temp=hash_table[index];
- X ptr=hash_table[index]=(host_ip_ent *)malloc(sizeof(host_ip_ent));
- X ptr->h_nxt=temp;
- X ptr->h_addr=h_addr;
- X if ((host=gethostbyaddr(&h_addr,sizeof(int),AF_INET))!=NULL)
- X {
- X ptr->h_name=strdup(host->h_name);
- X }
- X else
- X {
- X ptr->h_name=strdup(inet_ntoa(&h_addr));
- X }
- X return(ptr->h_name);
- X}
- X
- X
- X
- X
- X
- X
- X
- X
- X
- END_OF_FILE
- if test 1850 -ne `wc -c <'hostname.c'`; then
- echo shar: \"'hostname.c'\" unpacked with wrong size!
- fi
- # end of 'hostname.c'
- fi
- if test -f 'patchlevel.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'patchlevel.h'\"
- else
- echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
- sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
- X#define PATCHLEVEL 1
- END_OF_FILE
- if test 21 -ne `wc -c <'patchlevel.h'`; then
- echo shar: \"'patchlevel.h'\" unpacked with wrong size!
- fi
- # end of 'patchlevel.h'
- fi
- if test -f 'screen.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'screen.c'\"
- else
- echo shar: Extracting \"'screen.c'\" \(819 characters\)
- sed "s/^X//" >'screen.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- END_OF_FILE
- if test 819 -ne `wc -c <'screen.c'`; then
- echo shar: \"'screen.c'\" unpacked with wrong size!
- fi
- # end of 'screen.c'
- fi
- if test -f 'sort.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sort.c'\"
- else
- echo shar: Extracting \"'sort.c'\" \(3393 characters\)
- sed "s/^X//" >'sort.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X#include <stdio.h>
- X#include "ethertop.h"
- X#include "buffer.h"
- X
- X#define subtract(x,y) ((x)>(y) ? (x)-(y) : (y)-(x))
- X
- void subtract_etherstat(new,old,diff)
- struct etherstat *new, *old;
- etherfloatstat *diff;
- X{
- X register unsigned int x;
- X float difftime;
- X difftime=(float) subtract(new->e_time.tv_seconds,old->e_time.tv_seconds)
- X + (subtract((float) new->e_time.tv_useconds , (float) old->e_time.tv_useconds)) / 1000000.00;
- X diff->e_time=difftime;
- X diff->e_bytes =subtract(new->e_bytes,old->e_bytes)/difftime;
- X diff->e_packets=subtract(new->e_packets,old->e_packets)/difftime;
- X diff->e_bcast =subtract(new->e_bcast,old->e_bcast)/difftime;
- X for (x=0; x<NPROTOS; x++)
- X {
- X diff->e_proto[x]=subtract(new->e_proto[x],old->e_proto[x])/difftime;
- X }
- X for (x=0; x<NBUCKETS; x++)
- X {
- X diff->e_size[x]=subtract(new->e_size[x],old->e_size[x])/difftime;
- X }
- X}
- X
- X
- X
- X
- int size_compare(a,b)
- etherfloat_node **a,**b;
- X{
- X if ((*b)->h_cnt < (*a)->h_cnt)
- X return -1;
- X if((*b)->h_cnt > (*a)->h_cnt)
- X return 1;
- X return 0;
- X}
- X
- X
- void subtract_and_sort_etheraddrs(new, old, buf)
- X struct etheraddrs *new,*old;
- X buffer *buf;
- X{
- X register unsigned int i;
- X register float difftime;
- X etherhmem_node *newptr, *oldptr;
- X etherfloat_node *diffptr;
- X difftime=(float) subtract(new->e_time.tv_seconds,old->e_time.tv_seconds)
- X + (subtract((float) new->e_time.tv_useconds , (float) old->e_time.tv_useconds)) / 1000000.00;
- X
- X for (i=0; i<HASHSIZE; i++)
- X {
- X newptr=new->e_addrs[i];
- X oldptr=old->e_addrs[i];
- X while(newptr!=NULL) /* not a valid record */
- X {
- X while (oldptr!=NULL && /* old record is there */
- X oldptr->h_addr!=newptr->h_addr) /* but record has been inserted */
- X {
- X oldptr=oldptr->h_nxt; /* jump to next old address until you reach end */
- X /* or addresses match */
- X }
- X if (oldptr==NULL) /* old record does not exist */
- X {
- X diffptr=(etherfloat_node *)malloc(sizeof(etherfloat_node));
- X diffptr->h_addr=newptr->h_addr;
- X diffptr->h_cnt=(float)(newptr->h_cnt) / difftime;
- X add_buffer(buf,diffptr);
- X }
- X else /* old record existed */
- X {
- X if (newptr->h_cnt!=oldptr->h_cnt) /* count different */
- X {
- X diffptr=(etherfloat_node *)malloc(sizeof(etherfloat_node));
- X diffptr->h_addr=newptr->h_addr;
- X diffptr->h_cnt=(float) (subtract(newptr->h_cnt,oldptr->h_cnt)/difftime);
- X add_buffer(buf,diffptr);
- X }
- X oldptr=oldptr->h_nxt;
- X }
- X newptr=newptr->h_nxt;
- X }
- X }
- X qsort( (char *) buf->p, buf->end, sizeof(void *), size_compare);
- X}
- X
- X
- END_OF_FILE
- if test 3393 -ne `wc -c <'sort.c'`; then
- echo shar: \"'sort.c'\" unpacked with wrong size!
- fi
- # end of 'sort.c'
- fi
- if test -f 'sort.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sort.h'\"
- else
- echo shar: Extracting \"'sort.h'\" \(884 characters\)
- sed "s/^X//" >'sort.h' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1991 Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Irvine. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X
- void subtract_and_sort_etheraddrs();
- void subtract_etherstat();
- END_OF_FILE
- if test 884 -ne `wc -c <'sort.h'`; then
- echo shar: \"'sort.h'\" unpacked with wrong size!
- fi
- # end of 'sort.h'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-